//
//  Parameter.m
//  FrameWork
//
//  Created by Eagle on 5/26/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Parameter.h"
#import "FileTools.h"
#import "UIDefine.h"

@implementation Parameter



static Parameter * _sharedParameter;
+(Parameter *)sharedParameter
{
	if (!_sharedParameter) {
		_sharedParameter = [[self alloc] init];
	}
	
	return _sharedParameter;
}

+(id) alloc
{
	NSAssert(_sharedParameter == nil, @"Parameter,Attempted to allocate a second instance of a singleton.");
	return [super alloc];
}


-(id) init
{
	if( (self=[super init]) ) 
	{
		//第几关
		_stageNum = 0;
		
		openStage = 3;
		
		//初始金钱
		_beginMoney[0] = 10000;
		_beginMoney[1] = 20000;
		_beginMoney[2] = 30000;
		_beginMoney[3] = 40000;
		
		//波数
		_waveNumber[0] = 10;
		_waveNumber[1] = 20;
		_waveNumber[2] = 30;
		_waveNumber[3] = 40;
		
		//城市血量
		_cityHp[0] = 10;
		_cityHp[1] = 20;
		_cityHp[2] = 30;
		_cityHp[3] = 40;
		
		
		
		//敌兵基础生命参数
		_hpEnemy[0] = 60;
		_hpEnemy[1] = 110;
		_hpEnemy[2] = 85;
		_hpEnemy[3] = 260;
		_hpEnemy[4] = 180;
		_hpEnemy[5] = 150;
		_hpEnemy[6] = 400;
		_hpEnemy[7] = 500;
		
		//敌兵移动速度
		_speedEnemy[0] = 1.5;
		_speedEnemy[1] = 1.5;
		_speedEnemy[2] = 2.5;
		_speedEnemy[3] = 1.0;
		_speedEnemy[4] = 2.0;
		_speedEnemy[5] = 2.5;
		_speedEnemy[6] = 1.0;
		_speedEnemy[7] = 1.5;
		
		//敌兵金钱
		_moneyEnemy[0] = 4;
		_moneyEnemy[1] = 7;
		_moneyEnemy[2] = 9;
		_moneyEnemy[3] = 10;
		_moneyEnemy[4] = 14;
		_moneyEnemy[5] = 15;
		_moneyEnemy[6] = 16;
		_moneyEnemy[7] = 30;
		
		//敌兵经验
		_expEnemy[0] = 15;
		_expEnemy[1] = 15;
		_expEnemy[2] = 20;
		_expEnemy[3] = 20;
		_expEnemy[4] = 20;
		_expEnemy[5] = 30;
		_expEnemy[6] = 30;
		_expEnemy[7] = 50;
		
		//敌兵战功
		_exploitEnemy[0] = 50;
		_exploitEnemy[1] = 50;
		_exploitEnemy[2] = 50;
		_exploitEnemy[3] = 50;
		_exploitEnemy[4] = 50;
		_exploitEnemy[5] = 50;
		_exploitEnemy[6] = 50;
		_exploitEnemy[7] = 100;
		
		
		//普通箭塔攻击参数
		_attackTower[0] = 45;
		_attackTower[1] = 80;
		_attackTower[2] = 160;
		
		//半径
		_towerRadius[0] = 64; 
		_towerRadius[1] = 80; 
		_towerRadius[2] = 80; 
		
		//买
		_towerPrice[0] = 35;
		_towerPrice[1] = 50;
		_towerPrice[2] = 120;
		
		//卖
		_towerSellPrice[0] = 18;
		_towerSellPrice[1] = 25;
		_towerSellPrice[2] = 60;
		
		//间隔
		_towerInterval[0] = 23;
		_towerInterval[1] = 18;
		_towerInterval[2] = 14;
		
		//攻击角度
		_towerAttackDegree[0] = 22.5;
		_towerAttackDegree[1] = 22.5;
		_towerAttackDegree[2] = 22.5;
		
		//转速
		_towerTurnSpeed[0] = 4.5;
		_towerTurnSpeed[1] = 4.5;
		_towerTurnSpeed[2] = 4.5;
		
		//毒刺塔攻击力
		_attackPoison[0] = 20;
		_attackPoison[1] = 35;
		_attackPoison[2] = 70;
		
		//半径
		_poisonRadius[0] = 64;
		_poisonRadius[1] = 80;
		_poisonRadius[2] = 80;
		
		//买
		_poisonPrice[0] = 25;
		_poisonPrice[1] = 65;
		_poisonPrice[2] = 150;
		
		//卖
		_poisonSellPrice[0] = 13;
		_poisonSellPrice[1] = 33;
		_poisonSellPrice[2] = 75;
		
		//间隔
		_poisonInterval[0] = 26;
		_poisonInterval[1] = 22;
		_poisonInterval[2] = 18;
		
		//毒刺塔减速参数
		_slowdown[0] = 0.25;
		_slowdown[1] = 0.4;
		_slowdown[2] = 0.6;
		
		//减速时间,frame基准
		_slowdownTime[0] = 120;
		_slowdownTime[1] = 240;
		_slowdownTime[2] = 360;
		
		//攻击角度
		_poisonAttackDegree[0] = 22.5;
		_poisonAttackDegree[1] = 22.5;
		_poisonAttackDegree[2] = 22.5;
		
		//转速
		_poisonTurnSpeed[0] = 4.5;
		_poisonTurnSpeed[1] = 4.5;
		_poisonTurnSpeed[2] = 4.5;
		
		
		//穿刺攻击参数
		_attackPuncture[0] = 90;
		_attackPuncture[1] = 140;
		_attackPuncture[2] = 280;
		
		//半径
		_punctureRadius[0] = 80;
		_punctureRadius[1] = 96;
		_punctureRadius[2] = 96;
		
		//买
		_puncturePrice[0] = 100;
		_puncturePrice[1] = 180;
		_puncturePrice[2] = 300;
		
		//卖
		_punctureSellPrice[0] = 50;
		_punctureSellPrice[1] = 90;
		_punctureSellPrice[2] = 150;
		
		
		//间隔
		_punctureInterval[0] = 26;
		_punctureInterval[1] = 22;
		_punctureInterval[2] = 18;
		
		//攻击角度
		_punctureAttackDegree[0] = 22.5;
		_punctureAttackDegree[1] = 22.5;
		_punctureAttackDegree[2] = 22.5;
		
		//转速
		_punctureTurnSpeed[0] = 4.5;
		_punctureTurnSpeed[1] = 4.5;
		_punctureTurnSpeed[2] = 4.5;
		
		
		
		//投石车攻击力
		_attackMangonel[0] = 30;
		_attackMangonel[1] = 50;
		_attackMangonel[2] = 100;
		
		
		//半径
		_mangonelRadius[0] = 80;
		_mangonelRadius[1] = 96;
		_mangonelRadius[2] = 96;
		
		//买
		_mangonelPrice[0] = 75;
		_mangonelPrice[1] = 120;
		_mangonelPrice[2] = 250;
		
		
		//卖
		_mangonelSellPrice[0] = 38; 
		_mangonelSellPrice[1] = 60;
		_mangonelSellPrice[2] = 125;
		
		//间隔
		_mangonelInterval[0] = 30;
		_mangonelInterval[1] = 26;
		_mangonelInterval[2] = 22;
		
		//投石车伤害半径
		_radiusMangonel[0] = 60;
		_radiusMangonel[1] = 60;
		_radiusMangonel[2] = 60;
		
		//攻击角度
		_mangonelAttackDegree[0] = 22.5;
		_mangonelAttackDegree[1] = 22.5;
		_mangonelAttackDegree[2] = 22.5;
		
		//转速
		_mangonelTurnSpeed[0] = 4.5;
		_mangonelTurnSpeed[1] = 4.5;
		_mangonelTurnSpeed[2] = 4.5;
		
		
		//战鼓参数
		//影响半径
		_zhanguRadius[0] = 80;
		_zhanguRadius[1] = 96;
		_zhanguRadius[2] = 96;
		
		//增加攻击力
		_zhanguAttackUp[0] = 40;
		_zhanguAttackUp[1] = 60;
		_zhanguAttackUp[2] = 120;
		
		//买
		_zhanguPrice[0] = 110;
		_zhanguPrice[1] = 220;
		_zhanguPrice[2] = 350;
		
		//卖
		_zhanguSellPrice[0] = 55;
		_zhanguSellPrice[1] = 110;
		_zhanguSellPrice[2] = 175;
		
		
	}
	return self;
}

-(void) LoadFile
{
	[self LoadWarrior];
	[self LoadEnemy];
	[self LoadEffect];
}

-(float)RadiusArrowWeapon:(int)WeaponName Level:(int)lever
{
	switch (WeaponName) {
		case NormalWeapon:
		{
			return [[Parameter sharedParameter] radiusArrow:lever];
			break;
		}	
		case Poison:
		{
			return [[Parameter sharedParameter] radiusPoison:lever];
			break;
		}
		case Puncture:
		{
				return [[Parameter sharedParameter] radiusPuncture:lever];
			break;
		}
		case Mangonel:
		{
				return [[Parameter sharedParameter] radiusMangonel:lever];
			break;
		}
		case PowerUpTower:
		{
				return [[Parameter sharedParameter] radiusZhangu:lever];
			break;
		}
		default:
		{
				return [[Parameter sharedParameter] radiusPoison:lever];
			break;
		}
	}
	
}

-(void) LoadWarrior
{
	int i = 0;
	
	char rd[7][32];
	for (i = 0; i < 99; i++)
	{
		memset(rd, 0, sizeof(rd));
		readcsv("warrior.csv", ';', 7, i, &rd[0][0], 32);
		
		_warriorSpeed[i] = atof(rd[0]);
		
		
		
		//攻击间隔
		_warriorInterval[i] = atoi(rd[1]);
		
		//动画间隔
		_warriorAniTime[i] = atoi(rd[2]);
		
		//攻击半径
		_warriorAttackRadius[i] = atof(rd[3]);
		
		//守备半径
		_warriorGuardRadius[i] = atof(rd[4]);
		
		//升级所需经验值
		_warriorLevelExp[i] = atoi(rd[5]);
		
		//攻击力
		_warriorAttack[i] = atof(rd[6]);
		
	} 
	
}

//读取士兵参数
-(void) LoadEnemy
{
	int i = 0;
	char rd[5][32];
	
	for (i = 0; i < 8; i++) 
	{
		memset(rd, 0, sizeof(rd));
		readcsv("Enemy.csv", ';', 5, i, &rd[0][0], 32);
		
		_hpEnemy[i] = atof(rd[0]);
		_speedEnemy[i] = atof(rd[1]);
		_expEnemy[i] = atoi(rd[2]);
		_moneyEnemy[i] = atoi(rd[3]);
		_exploitEnemy[i] = atoi(rd[4]);
		
	}
}

//读取塔的参数
-(void) LoadTower
{
	
}

//读取技能参数
-(void) LoadEffect
{
	int i = 0;
	
	//落雷术参数读取
	char rd[3][32];
	
	for (i = 0; i < 99; i++) 
	{
		memset(rd, 0, sizeof(rd));
		readcsv("LuoLei.csv", ';', 3, i, &rd[0][0], 32);
		_luoLeiAttack[i] = atof(rd[0]);
		_luoLeiRadius[i] = atof(rd[1]);
		_luoLeiAttackTime[i] = atoi(rd[2]);
	}
	
	//偷取术参数读取
	char touqu[2][32];
	memset(touqu, 0, sizeof(touqu));
	readcsv("TouQu.csv", ';', 2, 0, &touqu[0][0], 32);
	_touQuRadius = atof(touqu[0]);
	_touQuLastTime = atoi(touqu[1]);
	
	
	//八卦参数读取
	char bagua[2][32];
	memset(bagua, 0, sizeof(bagua));
	readcsv("BaGua.csv", ';', 2, 0, &bagua[0][0], 32);
	_baGuaRadius = atof(bagua[0]);
	_baGuaLastTime = atoi(bagua[1]);
	
	//暴击参数读取
	
	char baoji[2][32];
	memset(baoji, 0, sizeof(baoji));
	readcsv("BaGua.csv", ';', 2, 0, &baoji[0][0], 32);
	_BaoJiAttackFactor = atof(baoji[0]);
	_BaoJiTime = atoi(baoji[1]);
	
}





//关卡数据
-(int) stage
{
	return _stageNum;
}

-(void) setStage:(int) stage
{
	_stageNum = stage;
}

//敌兵数据
-(float) hpEnemy:(int) type
{
	return _hpEnemy[type - 1];
	
}
-(float) speedEnemy:(int) type
{
	
	return _speedEnemy[type - 1];
	
}

-(int) moneyEnemy:(int) type
{
	return _moneyEnemy[type - 1];
}

-(int) expEnemy:(int) type
{
	return _expEnemy[type - 1];
}

-(int) exploitEnemy:(int) type
{
	return _exploitEnemy[type - 1];
}

//箭塔数据
-(float) attackArrow:(int) level
{
	return _attackTower[level - 1];
	
}

-(float) radiusArrow:(int) level
{
	return _towerRadius[level - 1];

}

-(int) priceArrow:(int) level
{
	return _towerPrice[level - 1];

}


-(int) sellPriceArrow:(int) level
{
	return _towerSellPrice[level - 1];
	
}

-(int) intervalArrow:(int) level
{
	return _towerInterval[level - 1];
}

-(float) attackDegreeArrow:(int) level
{
	return _towerAttackDegree[level - 1];
}

-(float) turnSpeedArrow:(int) level
{
	return _towerTurnSpeed[level - 1];
}


//毒刺数据
-(float) attackPoison:(int) level
{
	return _attackPoison[level - 1];
}

-(float) radiusPoison:(int) level
{
	return _poisonRadius[level  - 1];
}

-(int) pricePoison:(int) level
{
	return _poisonPrice[level - 1];
}

-(int) sellPricePoison:(int) level
{
	return _poisonSellPrice[level - 1];
}

-(int) intervalPoison:(int) level
{
	return _poisonInterval[level - 1];
}

-(float) slowdown:(int) level
{
	return _slowdown[level - 1];
}


-(int) slowdownTime:(int) level
{
	return _slowdownTime[level - 1];
}

-(float) attackDegreePoison:(int) level
{
	return _poisonAttackDegree[level - 1];
}

-(float) turnSpeedPoison:(int) level
{
	return _poisonTurnSpeed[level - 1];
}

//穿刺数据
-(float) attackPuncture:(int) level
{
	return _attackPuncture[level - 1];
}

-(float) radiusPuncture:(int) level
{
	return _punctureRadius[level - 1];
}

-(int) pricePuncture:(int) level
{
	return _puncturePrice[level - 1];
}

-(int) sellPricePuncture:(int) level
{
	return _punctureSellPrice[level - 1];
}

-(int) intervalPuncture:(int) level
{
	return _punctureInterval[level - 1];
}

-(float) attackDegreePuncture:(int) level
{
	return _punctureAttackDegree[level - 1];
}

-(float) turnSpeedPuncture:(int) level
{
	return _punctureTurnSpeed[level - 1];
}


//投石数据
-(float) attackMangonel:(int) level
{
	return _attackMangonel[level - 1];
}

-(float) radiusMangonel:(int) level
{
	return _mangonelRadius[level - 1];
}

-(int) priceMangonel:(int) level
{
	return _mangonelPrice[level - 1];
}

-(int) sellPriceMangonel:(int) level
{
	return _mangonelSellPrice[level - 1];
}

-(int) intervalMangonel:(int) level
{
	return _mangonelInterval[level - 1];
}

-(float) attackMangonelRadius:(int) level
{
	return _radiusMangonel[level - 1];
}

-(float) attackDegreeMangonel:(int) level
{
	return _mangonelAttackDegree[level - 1];
}

-(float) turnSpeedMangonel:(int) level
{
	return _mangonelTurnSpeed[level - 1];
}


//战鼓数据
-(float) attackUpZhangu:(int) level
{
	return _zhanguAttackUp[level - 1];
}

-(float) radiusZhangu:(int) level
{
	return _zhanguRadius[level - 1];
}

-(int) priceZhangu:(int) level
{
	return _zhanguPrice[level - 1];
}

-(int) sellPriceZhangu:(int) level
{
	return _zhanguSellPrice[level - 1];
}

//武将数据

//攻击
-(float) warriorAttack:(int) level
{
	return _warriorAttack[level - 1];
}

//升级经验
-(int) warriorLevelExp:(int) level
{
	return _warriorLevelExp[level - 1];
}


-(int) warriorAniTime:(int)level
{
	return _warriorAniTime[level - 1];
}

-(int) warriorInterval:(int) level
{
	return _warriorInterval[level - 1];
}


-(float) warriorSpeed:(int) level
{
	return _warriorSpeed[level - 1];
}


-(float) warriorAttackRadius:(int) level
{
	return _warriorAttackRadius[level - 1];
}


-(float) warriorGuardRadius:(int) level
{
	return _warriorGuardRadius[level - 1];
}


//技能参数
//落雷参数
-(float) luoLeiAttack:(int) level
{
	return _luoLeiAttack[level - 1];
}

-(float) luoLeiRadius:(int) level
{
	return _luoLeiRadius[level - 1];
}

-(int) luoLeiAttackTime:(int) level
{
	return _luoLeiAttackTime[level - 1];
}

//偷取术参数
//偷取术半径
-(float) touQuRadius
{
	return _touQuRadius;
}

//偷取术作用时间
-(int) touQuLastTime
{
	return _touQuLastTime;
}


//八卦阵参数
//八卦阵半径
-(float) baGuaRadius
{
	return _baGuaRadius;
}

//八卦阵作用时间
-(int) baGuaLastTime
{
	return _baGuaLastTime;
}

//暴击参数
//暴击攻击力因子
-(float) BaoJiAttackFactor
{
	return _BaoJiAttackFactor;
}
//暴击次数
-(int) BaoJiTime
{
	return _BaoJiTime;
}

//////////waver 2010/8/6
-(BOOL)IsStageOpen:(int)stageNum
{
	if(stageNum < openStage)
	{
		return YES;
	}
	return NO;
}


-(int) beginMoney:(int)lever
{
	return _beginMoney[lever];
}

-(int)waveNumber:(int)lever
{
	return _waveNumber[lever];
}

-(int)cityHp:(int)lever
{
	return _cityHp[lever];
}


@end
